<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/common.jsp" %>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>借贷管理系统后台</title>
<style type="text/css">
	tr {
		height:40px;
	}
</style>
<script type="text/javascript">
$(function(){
	$('#dd').dialog({
	    title: "新增用户",
	    closed:false,
	    modal: true, //dialog继承自window，而window里面有modal属性，所以dialog也可以使用
	    toolbar: [{
				text:'Ok',
			iconCls:'icon-ok',
			handler:function(){
				$('#ff').form('submit',{
					onSubmit:function(){
						var isValid = $(this).form('validate');
						return isValid;
					},
					success: function(r){
						if(r>0){
							$.messager.show({
								title:"Success！",
								msg:"恭喜您，注册成功，此页面3秒后自动关闭！"
							})
							setTimeout(window.close(),3000)
						}else{
							$.messager.show({
								title:"Error！",
								msg:"抱歉，操作失败！"
							})
						}
						$('#ff').form('clear');
						$('#dd').dialog('close');
					}
				});
			
			}
		},{
			text:'Cancel',
			handler:function(){
				$('#dd').dialog('close');
				$('#ff').form('clear');
			}
		}],
		onClose: function() {
			$('#ff').form('clear');
		}
	});
	 var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}   
     function isCardID(sId){   
         var iSum=0 ;  
         var info="" ;  
         if(!/^\d{17}(\d|x)$/i.test(sId)) return "你输入的身份证长度或格式错误";   
         sId=sId.replace(/x$/i,"a");   
         if(aCity[parseInt(sId.substr(0,2))]==null) return "你的身份证地区非法";   
         sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));   
         var d=new Date(sBirthday.replace(/-/g,"/")) ;  
         if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "身份证上的出生日期非法";   
         for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11) ;  
         if(iSum%11!=1) return "你输入的身份证号非法";   
         return true;//aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女")   
     }
     $.extend($.fn.validatebox.defaults.rules, {     
     	    idcared: {     
     	        validator: function(value,param){    
     	            var flag= isCardID(value);  
     	            return flag==true?true:false;    
     	        },     
     	        message: '不是有效的身份证号码'    
     	    },
     	 phone:{     
		        validator: function(value,param){
		        	var flag=/^1[3|4|5|8][0-9]\d{4,8}$/.test(value);
		        	return flag==true?true:false; 
		        },     
		        message: '手机号不合法!'    
		    },
	     username: {     
		        validator: function(value,param){    
		        	var flag=false;
		        	$.ajax({
		        		type:"post",
		        		url:"${cs}/exitsUsername",
		        		data:"username="+value,
		        		dataType:"json",
		        		async : false,
		        		success:function(result){
    	    				flag=result;
    	    			}
		        	},'json')
		        	return flag==true?true:false; 
		        },     
		        message: '账户信息已存在！'    
		    },
		    equalTo: { validator: function (value, param) { return $(param[0]).val() == value; }, message: '两次输入密码不一致！' }
     	}); 
})
</script>
</head>
<div class="easyui-layout" style="width:100%;height:100%;" data-options="fit:true">
				<div id="dd" title="新增用户"  style="width:400px;height:380px; text-align: center; " data-options="closed:false">
				    <form id="ff" method="post" action="${cs}/register" >
				    		<input type="hidden" id="id" name="id">
				    	<table cellpadding="5"  style="text-align: left;">
				    		<tr>
				    			<td>用户名:</td>
				    			<td><input class="easyui-textbox" type="text" id="username"  name="username"  data-options="required:true,validType:['length[6,15]','username']"  missingMessage="用户名不能为空"></input></td>
				    		</tr>
				    		<tr>
				    			<td>密码:</td>
				    			<td><input class="easyui-textbox" type="password" id="password"  name="password" validType="length[6,20]" data-options="required:true" missingMessage="密码不能为空"></input></td>
				    		</tr>
				    		<tr>
				    			<td>再次输入密码:</td>
				    			<td><input class="easyui-textbox" type="password" id="rpassword"  name="rpassword" data-options="required:true" validType="equalTo['#password']" missingMessage="请再次输入密码"></input></td>
				    		</tr>
				    		<tr>
				    			<td>身份证:</td>
				    			<td><input class="easyui-textbox" type="text"   name="idcard" data-options="required:true,validType:'idcared'"  missingMessage="身份证不能为空"></input></td>
				    		</tr>
				    		<tr>
				    			<td>手机:</td>
				    			<td><input class="easyui-textbox" type="text"   name="phone" data-options="required:true,validType:['length[11,11]','phone']"  missingMessage="手机号不能为空！"></input></td>
				    		</tr>
				    		<tr>
				    			<td>邮箱:</td>
				    			<td><input class="easyui-textbox" type="text"   name="email" data-options="required:true" validType="email" missingMessage="邮箱不能为空"></input></td>
				    		</tr>
				    	</table>
				    </form>
			   </div>
</div>
</body>
</html>